<%@ page import="com.useeinfo.framework.sugar.tools.DateTimeUtils" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 自动抄表
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <a href="javascript:;" class="btn btn-default" id="btnExport" title="导出"><i
                        class="glyphicon glyphicon-export"></i> 导出</a>
            </div>
        </div>
        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/wuhan/automatic/getAutomaticTableListJSON.action"/>"
                  method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">类型：</label>
                    <div class="control-inline">
                        <select id="meterReading" name="meterReading" class="form-control" onchange="getSelect()">
                            <option value="">全部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                            <c:forEach items="${selectVOS}" var="select">
                                <option value="${select.value}">${select.text}</option>
                            </c:forEach>
                        </select>
                    </div>

                    <label class="control-label">机组：</label>
                    <div class="control-inline">
                        <select id="select_unitId" name="select_unitId" class="form-control">
                            <option value="">全部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                        </select>
                    </div>

                    <label class="control-label">时间：</label>
                    <div class="control-inline">
                        <input type="text" class="form-control margin-right-10" id="date" name="date"
                               value="<%=DateTimeUtils.formatDateToString(new Date())%>"/>
                    </div>

                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    $("#date").datetimepicker({format: 'yyyy-mm-dd', minView: "month", autoclose: true});
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        shrinkToFit: false,
        autoScroll: true,
        columnModel: [
            {header: '机组', name: 'meterReadingName', width: 250, align: "center",sortable: false},
            {header: '设备', name: 'unit', width: 250, align: "center",sortable: false},
            {header: '点位', name: 'pointName', index: 'wuHanPoint.name', width: 250, align: "center"},
            {header: '备注', name: 'remark', index: 'wuHanPoint.remark', width: 250, align: "center"},
            {header: '阈值', name: 'threshold', index: 'threshold', width: 250, align: "center"},
            {header: '值', name: 'value', index: 'value', width: 250, align: "center",
                formatter: function (val, obj, row, act) {
                    if (row.isRed) {
                        return '<p style="color:red">' + row.value + '</p>'
                    }else {
                        return '<p style="color:black">' + row.value + '</p>'
                    }
                }
            },
            {header: '单位', name: 'unitOfMeasurement', index: 'unitOfMeasurement', width: 250, align: "center",sortable: false},
            {header: '系统', name: 'pointSystem', index: 'pointSystem', width: 250, align: "center",sortable: false},
            {header: '抄表时间', name: 'autoTime', index: 'createDate', width: 250, align: "center"},
            {header: '创建时间', name: 'createDate', index: 'createDate', width: 250, align: "center"}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });

    $('#btnExport').click(function () {
        if ($("#meterReading").val() == '') {
            js.showMessage("请选择类型！", '', "error");
        }
        if ($("#date").val() == '') {
            js.showMessage("请选择时间！", '', "error");
        }
        js.ajaxSubmitForm($('#searchForm'), {
            url: '<c:url value="/web/wuhan/automatic/generateAutomaticMeterReading.action"/>',
            downloadFile: true
        });

    });

    function getSelect(){
        $("#select_unitId").empty();
        $("#select_unitId").append("<option value=\"\">全部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>");
        var meterReading = $("#meterReading").val();
        if (meterReading == null || meterReading == '' || meterReading == undefined) {
            meterReading="";
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '<c:url value="/web/wuhan/unit/getWuHanUnitSelectByMeterReading.action"/>',
            data: {
                meterReading: meterReading
            },
            async: false,
            success: function (html) {
                if(html.status==0){
                    $.each(html.data, function(idx, obj) {
                        $("#select_unitId").append("<option value='"+obj.id+"'>"+obj.unit+"</option>");
                    });
                }
            },
            error: function () {
                alert('ajax error!');
            }
        });

    }


</script>